/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package bean.business;

import entities.ReEvaluation;
import java.util.List;
import javax.ejb.Stateless;
import javax.ejb.LocalBean;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

/**
 *
 * @author HoangHai
 */
@Stateless
@LocalBean
public class reEvaluationBean {
    @PersistenceContext(unitName = "DeclarationBoard-ejbPU")
    private EntityManager em;

    public void persist(Object object) {
        em.persist(object);
    }

    // Add business logic below. (Right-click in editor and choose
    // "Insert Code > Add Business Method")
    public List<ReEvaluation> allReEvaluation(){
        List<ReEvaluation> reEvaluations = em.createNamedQuery("ReEvaluation.findAll").getResultList();
        return reEvaluations;
    }
    public ReEvaluation findReEvaluationByID(int id){
        ReEvaluation reEvaluation = (ReEvaluation) em.createNamedQuery("ReEvaluation.findByReID").setParameter("reID", id).getSingleResult();
        return reEvaluation;
    }
    public boolean addReEvaluation(ReEvaluation re){
        boolean isOk = false;
        try {
            em.persist(re);
            isOk = true;
        } catch (Exception e) {
            isOk = false;
        }
        return isOk;
    }
    public boolean updateReEvaluation(ReEvaluation re){
        boolean isOk = false;
        try {
            em.merge(re);
            isOk = true;
        } catch (Exception e) {
            isOk = false;
        }
        return isOk;
    }
    public boolean delReEvaluation(int id){
        boolean isOk = false;
        try {
            ReEvaluation re = findReEvaluationByID(id);
            em.remove(re);
            isOk = true;
        } catch (Exception e) {
            isOk = false;
        }
        return isOk;
    }
}
